package wumpus;

public class WumpusGrader
{
    public static void main(String args[])
    {
        if (args.length < 2) {
            System.out.println("Usage: <classname> <niters>");
            return;
        }

        String agentname = args[0];
        int niters = Integer.parseInt(args[1]);

        int totalscore = 0;
        long starttime = System.currentTimeMillis();

        for (int iter = 0; iter < niters; iter++) {

            WumpusState state = new WumpusState(iter, 4, 3);

            WumpusAgent agent = (WumpusAgent) ReflectUtil.createObject(args[0]);
            agent.init(state.width, state.height);

            while (!state.isGameOver()) {

                String move = agent.getMove(state.isBreezy(state.agentx, state.agenty),
                                            state.isSmelly(state.agentx, state.agenty),
                                            state.hasGold(state.agentx, state.agenty));

                state.performMove(move);
            }

            System.out.printf("========== GAME %d SCORE %d ===========\n", iter, state.score);
            totalscore += state.score;
        }

        double dt = (System.currentTimeMillis() - starttime) / 1000.0;

        System.out.printf("AVERAGE SCORE %f, %15f seconds\n", totalscore / ((double) niters), dt);
    }
}
